/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RENDER_OBJ_WIDGET_HH
#define RENDER_OBJ_WIDGET_HH
//! \addtogroup introsight_framework
//@{

// INCLUDES
#include "render_obj.hh"
#include "render_attr.hh"

// TYPES
class render_mng;

class render_obj_widget: public render_obj
{
protected:
    // cube specification
    float dims[IS_3D];
    bool independent;  // if true, the object has a 3D shape and is root of rest of widgets under it

    struct independent_data_str
    {
	// color changes
	render_color_anim color;
	unsigned char color_nonselect[IS_RGBA];
	unsigned char color_select[IS_RGBA];
	unsigned char color_cselect[IS_RGBA];
	unsigned color_anim_usec;

	// precalc pass info
	float distance;    // to camera
	float infront;     // measure of how in front camera is from me [-1:1] (<0 back)
	float front_blend; // dependant of distance and infront [:1] (<0 do not display contents)
	float pixel_to_dims_ratio;
	float dims_to_pixel_ratio;

	// movement
	float depth;
	float velo, velo_att[2];
    } *independent_data;

    // widget parameters (to be used only while in render)
    static render_obj_widget *root;

    // common widget parameters
    int depth_init;
    float size[IS_2D]; // required size to show perfectly or negative pressure (this is pre-calculated)

    enum widget_align
    {
	widget_align_left=0,
	widget_align_center,
	widget_align_right
    };

    struct widget_params
    {
	int depth;
	widget_align align[IS_2D];
	float text_color[IS_RGBA];
	float text_size;   // 1.0 means it should be rendered at font pixel size when camera in correct position

	void dump();
    } *params;
    int n_params, max_params;

    // PRIVATE METHODS
    void ctor();
    void dtor();

    // render functions
    void render_base(render_mng *ctx);
    void render_base_end(render_mng *ctx);
    void render_back_and_lateral(float color[IS_RGBA]);
    void render_lateral(double half_dims[IS_2D]);
    void render_front(render_mng *ctx);
    void render_cube_select();
    void render_set_2d();

    void check_independent_data();

public:
    render_obj_widget();
    virtual ~render_obj_widget();

    virtual bool init(render_mng *ctx);
    virtual void render(render_mng *ctx);
    virtual bool event(render_mng *ctx);
    virtual unsigned get_type();           // returns IS_TYPE_*

    inline float get_infront() {return independent_data->infront;}
    inline float get_pixel_to_dims_ratio() {return independent_data->pixel_to_dims_ratio;}
    inline float get_dims_to_pixel_ratio() {return independent_data->dims_to_pixel_ratio;}
    inline float get_front_blend() {return independent_data->front_blend;}
    inline void set_front_blend(float blend) {independent_data->front_blend=blend;}

    inline void set_dim(int idx, float value) {dims[idx]=value;}

    inline float get_depth() {return independent_data->depth;}
    void add_param(widget_params *param);
    void dump_params();
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	render_obj_widget
	{
		# members
		dims,
		independent,
		independent_data,
		color,
		color_nonselect,
		color_select,
		color_cselect,
		color_anim_usec,
		depth_init,
		params, n_params, max_params:
						select

		# methods
		init, render,
		add_param,
		dump_params:
						select
	}
   )
*/
